/*
 * @lc app=leetcode.cn id=897 lang=javascript
 *
 * [897] 递增顺序查找树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var increasingBST = function(root) {
    if(!root)return []
    let arr=[]
    let dfs=function(node){
        if(!node)return 
        dfs(node.left)
        arr.push(node.val)
        dfs(node.right)
    }
    dfs(root)
    let temp=cur=new TreeNode(arr[0])
    for(let i=1;i<arr.length;i++){
        cur.right=new TreeNode(arr[i])
        cur.left=null
        cur=cur.right
    }    
    return temp
};//数组版
// @lc code=end

var increasingBST = function(root) {
    let temp=cur=new TreeNode(null)
    let dfs=function(node){
        if(!node)return
        dfs(node.left)
        cur.right=new TreeNode(node.val)
        cur=cur.right
        dfs(node.right)
    }
    dfs(root)
    return temp.right
    
};//good